package com.itao;

import org.apache.poi.ss.usermodel.*;

/**
 * @author sjt
 * @Date 2025/7/23 15:38
 */
public class PoiUtil {

    /**
     * 水平居中，垂直居中
     * 上下左右边框
     * 仿宋_GB2312 12号
     */
    public static CellStyle cellStyle1(Workbook workbook){
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short)12);
        font.setFontName("仿宋_GB2312");
        cellStyle.setFont(font);
        return cellStyle;
    }

    /**
     * 垂直居中
     * 上下左右边框
     * 仿宋_GB2312 12号
     * 自动换行
     */
    public static CellStyle cellStyle2(Workbook workbook){
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short)12);
        font.setFontName("仿宋_GB2312");
        cellStyle.setFont(font);
        cellStyle.setWrapText(true);
        return cellStyle;
    }

    /**
     * 垂直居中
     * 上下左右边框
     * 仿宋_GB2312 12号 加粗
     */
    public static CellStyle cellStyle3(Workbook workbook){
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short)12);
        font.setBold(true);
        font.setFontName("仿宋_GB2312");
        cellStyle.setFont(font);
        return cellStyle;
    }
}
